{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 原始网页：https://news.qq.com/zt2020/page/feiyan.htm#/\n",
    "### 1. 数据提取部分"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.1 导入模块"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 如果使用本地静态资源，需要在头部声明"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 只需要在顶部声明 CurrentConfig.ONLINE_HOST 即可(针对notebook)\n",
    "# from pyecharts.globals import CurrentConfig, OnlineHostType\n",
    "# # OnlineHostType.NOTEBOOK_HOST 默认值为 http://localhost:8888/nbextensions/assets/\n",
    "# CurrentConfig.ONLINE_HOST = OnlineHostType.NOTEBOOK_HOST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "import time\n",
    "import datetime\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2022年8月21日'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "today = datetime.datetime.today()\n",
    "date = f'{today.year}年{today.month}月{today.day}日'\n",
    "date"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.2 获取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'today': {'local_confirm_add': 22130,\n",
       "   'abroad_confirm_add': 0,\n",
       "   'dead_add': 36,\n",
       "   'confirm': 22130,\n",
       "   'confirmCuts': 0,\n",
       "   'isUpdated': True,\n",
       "   'tip': '',\n",
       "   'wzz_add': 0},\n",
       "  'total': {'mtime': '2022-08-21 10:08:35',\n",
       "   'nowConfirm': 4997545,\n",
       "   'confirm': 5020895,\n",
       "   'wzz': 0,\n",
       "   'highRiskAreaNum': 0,\n",
       "   'continueDayZeroConfirmAdd': 0,\n",
       "   'heal': 13742,\n",
       "   'showHeal': True,\n",
       "   'provinceLocalConfirm': 0,\n",
       "   'continueDayZeroConfirm': 0,\n",
       "   'adcode': '',\n",
       "   'showRate': False,\n",
       "   'dead': 9608,\n",
       "   'mediumRiskAreaNum': 0,\n",
       "   'continueDayZeroLocalConfirmAdd': 0},\n",
       "  'children': [{'adcode': '',\n",
       "    'date': '2022/08/21',\n",
       "    'today': {'isUpdated': True,\n",
       "     'wzz_add': '',\n",
       "     'local_confirm_add': 22130,\n",
       "     'confirm': 22130,\n",
       "     'confirmCuts': 0},\n",
       "    'total': {'dead': 0,\n",
       "     'mediumRiskAreaNum': 0,\n",
       "     'adcode': '',\n",
       "     'showRate': False,\n",
       "     'provinceLocalConfirm': 0,\n",
       "     'highRiskAreaNum': 0,\n",
       "     'continueDayZeroLocalConfirmAdd': 0,\n",
       "     'mtime': '2022-08-21 10:37:34',\n",
       "     'showHeal': True,\n",
       "     'wzz': 0,\n",
       "     'heal': 0,\n",
       "     'continueDayZeroLocalConfirm': 0,\n",
       "     'nowConfirm': 5020895,\n",
       "     'confirm': 5020895},\n",
       "    'name': '地区待确认'}],\n",
       "  'name': '台湾',\n",
       "  'adcode': '',\n",
       "  'date': '2022/08/21'}]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url = \"https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=statisGradeCityDetail,diseaseh5Shelf\"\n",
    "response = requests.post(url)\n",
    "china_datas = response.json()[\"data\"][\"diseaseh5Shelf\"][\"areaTree\"][0][\"children\"]\n",
    "china_datas[:1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.3 解析提取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_set = []\n",
    "for data in china_datas:\n",
    "    data_dict = {\n",
    "        'province': data['name'], \n",
    "        'nowConfirm': data['total']['nowConfirm'], \n",
    "        'confirm': data['total']['confirm'], \n",
    "        'dead': data['total']['dead'], \n",
    "        'heal': data['total']['heal'], \n",
    "    } \n",
    "    data_set.append(data_dict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.4 生成表格对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>province</th>\n",
       "      <th>nowConfirm</th>\n",
       "      <th>confirm</th>\n",
       "      <th>dead</th>\n",
       "      <th>heal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>台湾</td>\n",
       "      <td>4997545</td>\n",
       "      <td>5020895</td>\n",
       "      <td>9608</td>\n",
       "      <td>13742</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>香港</td>\n",
       "      <td>290713</td>\n",
       "      <td>371999</td>\n",
       "      <td>9602</td>\n",
       "      <td>71684</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>海南</td>\n",
       "      <td>7136</td>\n",
       "      <td>7471</td>\n",
       "      <td>6</td>\n",
       "      <td>329</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广东</td>\n",
       "      <td>370</td>\n",
       "      <td>8701</td>\n",
       "      <td>8</td>\n",
       "      <td>8323</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>西藏</td>\n",
       "      <td>281</td>\n",
       "      <td>285</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>福建</td>\n",
       "      <td>189</td>\n",
       "      <td>3969</td>\n",
       "      <td>1</td>\n",
       "      <td>3779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>陕西</td>\n",
       "      <td>164</td>\n",
       "      <td>3554</td>\n",
       "      <td>3</td>\n",
       "      <td>3387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>天津</td>\n",
       "      <td>159</td>\n",
       "      <td>2116</td>\n",
       "      <td>3</td>\n",
       "      <td>1954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>上海</td>\n",
       "      <td>139</td>\n",
       "      <td>63762</td>\n",
       "      <td>595</td>\n",
       "      <td>63028</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>吉林</td>\n",
       "      <td>137</td>\n",
       "      <td>40309</td>\n",
       "      <td>5</td>\n",
       "      <td>40167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>浙江</td>\n",
       "      <td>128</td>\n",
       "      <td>3371</td>\n",
       "      <td>1</td>\n",
       "      <td>3242</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>四川</td>\n",
       "      <td>122</td>\n",
       "      <td>2840</td>\n",
       "      <td>3</td>\n",
       "      <td>2715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>北京</td>\n",
       "      <td>113</td>\n",
       "      <td>3933</td>\n",
       "      <td>9</td>\n",
       "      <td>3811</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>内蒙古</td>\n",
       "      <td>50</td>\n",
       "      <td>2340</td>\n",
       "      <td>1</td>\n",
       "      <td>2289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>山东</td>\n",
       "      <td>48</td>\n",
       "      <td>2916</td>\n",
       "      <td>7</td>\n",
       "      <td>2861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>新疆</td>\n",
       "      <td>41</td>\n",
       "      <td>1053</td>\n",
       "      <td>3</td>\n",
       "      <td>1009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>重庆</td>\n",
       "      <td>30</td>\n",
       "      <td>837</td>\n",
       "      <td>6</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>云南</td>\n",
       "      <td>29</td>\n",
       "      <td>2258</td>\n",
       "      <td>2</td>\n",
       "      <td>2227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>广西</td>\n",
       "      <td>28</td>\n",
       "      <td>2251</td>\n",
       "      <td>2</td>\n",
       "      <td>2221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>江西</td>\n",
       "      <td>24</td>\n",
       "      <td>1466</td>\n",
       "      <td>1</td>\n",
       "      <td>1441</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>黑龙江</td>\n",
       "      <td>23</td>\n",
       "      <td>3027</td>\n",
       "      <td>13</td>\n",
       "      <td>2991</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>辽宁</td>\n",
       "      <td>23</td>\n",
       "      <td>1772</td>\n",
       "      <td>2</td>\n",
       "      <td>1747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>青海</td>\n",
       "      <td>18</td>\n",
       "      <td>166</td>\n",
       "      <td>0</td>\n",
       "      <td>148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>河南</td>\n",
       "      <td>12</td>\n",
       "      <td>3242</td>\n",
       "      <td>22</td>\n",
       "      <td>3208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>江苏</td>\n",
       "      <td>11</td>\n",
       "      <td>2342</td>\n",
       "      <td>0</td>\n",
       "      <td>2331</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>山西</td>\n",
       "      <td>10</td>\n",
       "      <td>439</td>\n",
       "      <td>0</td>\n",
       "      <td>429</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>湖南</td>\n",
       "      <td>8</td>\n",
       "      <td>1420</td>\n",
       "      <td>4</td>\n",
       "      <td>1408</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>贵州</td>\n",
       "      <td>6</td>\n",
       "      <td>192</td>\n",
       "      <td>2</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>湖北</td>\n",
       "      <td>4</td>\n",
       "      <td>68413</td>\n",
       "      <td>4512</td>\n",
       "      <td>63897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>甘肃</td>\n",
       "      <td>4</td>\n",
       "      <td>1336</td>\n",
       "      <td>2</td>\n",
       "      <td>1330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>澳门</td>\n",
       "      <td>2</td>\n",
       "      <td>793</td>\n",
       "      <td>6</td>\n",
       "      <td>785</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>河北</td>\n",
       "      <td>1</td>\n",
       "      <td>2009</td>\n",
       "      <td>7</td>\n",
       "      <td>2001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>安徽</td>\n",
       "      <td>0</td>\n",
       "      <td>1504</td>\n",
       "      <td>6</td>\n",
       "      <td>1498</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>宁夏</td>\n",
       "      <td>0</td>\n",
       "      <td>122</td>\n",
       "      <td>0</td>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   province  nowConfirm  confirm  dead   heal\n",
       "0        台湾     4997545  5020895  9608  13742\n",
       "1        香港      290713   371999  9602  71684\n",
       "2        海南        7136     7471     6    329\n",
       "3        广东         370     8701     8   8323\n",
       "4        西藏         281      285     0      4\n",
       "5        福建         189     3969     1   3779\n",
       "6        陕西         164     3554     3   3387\n",
       "7        天津         159     2116     3   1954\n",
       "8        上海         139    63762   595  63028\n",
       "9        吉林         137    40309     5  40167\n",
       "10       浙江         128     3371     1   3242\n",
       "11       四川         122     2840     3   2715\n",
       "12       北京         113     3933     9   3811\n",
       "13      内蒙古          50     2340     1   2289\n",
       "14       山东          48     2916     7   2861\n",
       "15       新疆          41     1053     3   1009\n",
       "16       重庆          30      837     6    801\n",
       "17       云南          29     2258     2   2227\n",
       "18       广西          28     2251     2   2221\n",
       "19       江西          24     1466     1   1441\n",
       "20      黑龙江          23     3027    13   2991\n",
       "21       辽宁          23     1772     2   1747\n",
       "22       青海          18      166     0    148\n",
       "23       河南          12     3242    22   3208\n",
       "24       江苏          11     2342     0   2331\n",
       "25       山西          10      439     0    429\n",
       "26       湖南           8     1420     4   1408\n",
       "27       贵州           6      192     2    184\n",
       "28       湖北           4    68413  4512  63897\n",
       "29       甘肃           4     1336     2   1330\n",
       "30       澳门           2      793     6    785\n",
       "31       河北           1     2009     7   2001\n",
       "32       安徽           0     1504     6   1498\n",
       "33       宁夏           0      122     0    122"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data_set) \n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.5 数据永久性保存"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('./国内疫情数据.csv', encoding='utf-8-sig')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. 可视化操作部分"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.1 导入模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar, Line, Pie, Grid, Map"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.2 数据整理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>province</th>\n",
       "      <th>nowConfirm</th>\n",
       "      <th>confirm</th>\n",
       "      <th>dead</th>\n",
       "      <th>heal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>台湾</td>\n",
       "      <td>4997545</td>\n",
       "      <td>5020895</td>\n",
       "      <td>9608</td>\n",
       "      <td>13742</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>香港</td>\n",
       "      <td>290713</td>\n",
       "      <td>371999</td>\n",
       "      <td>9602</td>\n",
       "      <td>71684</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>海南</td>\n",
       "      <td>7136</td>\n",
       "      <td>7471</td>\n",
       "      <td>6</td>\n",
       "      <td>329</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广东</td>\n",
       "      <td>370</td>\n",
       "      <td>8701</td>\n",
       "      <td>8</td>\n",
       "      <td>8323</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>西藏</td>\n",
       "      <td>281</td>\n",
       "      <td>285</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>福建</td>\n",
       "      <td>189</td>\n",
       "      <td>3969</td>\n",
       "      <td>1</td>\n",
       "      <td>3779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>陕西</td>\n",
       "      <td>164</td>\n",
       "      <td>3554</td>\n",
       "      <td>3</td>\n",
       "      <td>3387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>天津</td>\n",
       "      <td>159</td>\n",
       "      <td>2116</td>\n",
       "      <td>3</td>\n",
       "      <td>1954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>上海</td>\n",
       "      <td>139</td>\n",
       "      <td>63762</td>\n",
       "      <td>595</td>\n",
       "      <td>63028</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>吉林</td>\n",
       "      <td>137</td>\n",
       "      <td>40309</td>\n",
       "      <td>5</td>\n",
       "      <td>40167</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  province  nowConfirm  confirm  dead   heal\n",
       "0       台湾     4997545  5020895  9608  13742\n",
       "1       香港      290713   371999  9602  71684\n",
       "2       海南        7136     7471     6    329\n",
       "3       广东         370     8701     8   8323\n",
       "4       西藏         281      285     0      4\n",
       "5       福建         189     3969     1   3779\n",
       "6       陕西         164     3554     3   3387\n",
       "7       天津         159     2116     3   1954\n",
       "8       上海         139    63762   595  63028\n",
       "9       吉林         137    40309     5  40167"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = df.sort_values(by=['nowConfirm'], ascending=False)[:10]\n",
    "df1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.3 可视化饼图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 提示：可视化前，将数据转换为列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('台湾', 4997545),\n",
       " ('香港', 290713),\n",
       " ('海南', 7136),\n",
       " ('广东', 370),\n",
       " ('西藏', 281),\n",
       " ('福建', 189),\n",
       " ('陕西', 164),\n",
       " ('天津', 159),\n",
       " ('上海', 139),\n",
       " ('吉林', 137)]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst = list(zip(df1['province'].values.tolist(),\n",
    "           df1['nowConfirm'].values.tolist()))\n",
    "lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"c01b063bf84a4a0d83cfe20407e5b4aa\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_c01b063bf84a4a0d83cfe20407e5b4aa = echarts.init(\n",
       "                    document.getElementById('c01b063bf84a4a0d83cfe20407e5b4aa'), 'white', {renderer: 'canvas'});\n",
       "                var option_c01b063bf84a4a0d83cfe20407e5b4aa = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"clockwise\": true,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u53f0\\u6e7e\",\n",
       "                    \"value\": 4997545\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9999\\u6e2f\",\n",
       "                    \"value\": 290713\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d77\\u5357\",\n",
       "                    \"value\": 7136\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": 370\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u85cf\",\n",
       "                    \"value\": 281\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\",\n",
       "                    \"value\": 189\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9655\\u897f\",\n",
       "                    \"value\": 164\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5929\\u6d25\",\n",
       "                    \"value\": 159\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": 139\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\",\n",
       "                    \"value\": 137\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"10%\",\n",
       "                \"30%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}:{c}\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u53f0\\u6e7e\",\n",
       "                \"\\u9999\\u6e2f\",\n",
       "                \"\\u6d77\\u5357\",\n",
       "                \"\\u5e7f\\u4e1c\",\n",
       "                \"\\u897f\\u85cf\",\n",
       "                \"\\u798f\\u5efa\",\n",
       "                \"\\u9655\\u897f\",\n",
       "                \"\\u5929\\u6d25\",\n",
       "                \"\\u4e0a\\u6d77\",\n",
       "                \"\\u5409\\u6797\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"left\": \"70%\",\n",
       "            \"top\": \"70%\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"2022\\u5e748\\u670821\\u65e5_\\u7701\\u4efd\\u5360\\u6bd4\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_c01b063bf84a4a0d83cfe20407e5b4aa.setOption(option_c01b063bf84a4a0d83cfe20407e5b4aa);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x12ffdfaf0>"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pie = (\n",
    "    Pie()\n",
    "    .add(\"\", lst, radius=[\"10%\", \"30%\"])\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=f'{date}_省份占比'),\n",
    "        legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"70%\", pos_left=\"70%\"))\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}:{c}\")))\n",
    "pie.render_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.4可视化地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'china':'https://assets.pyecharts.org/assets/maps/china'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"3026991247044c4396c3824afa37cd8d\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'china'], function(echarts) {\n",
       "                var chart_3026991247044c4396c3824afa37cd8d = echarts.init(\n",
       "                    document.getElementById('3026991247044c4396c3824afa37cd8d'), 'white', {renderer: 'canvas'});\n",
       "                var option_3026991247044c4396c3824afa37cd8d = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"mapType\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u53f0\\u6e7e\",\n",
       "                    \"value\": 4997545\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9999\\u6e2f\",\n",
       "                    \"value\": 290713\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d77\\u5357\",\n",
       "                    \"value\": 7136\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": 370\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u85cf\",\n",
       "                    \"value\": 281\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\",\n",
       "                    \"value\": 189\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9655\\u897f\",\n",
       "                    \"value\": 164\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5929\\u6d25\",\n",
       "                    \"value\": 159\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": 139\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\",\n",
       "                    \"value\": 137\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": 128\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\",\n",
       "                    \"value\": 122\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": 113\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5185\\u8499\\u53e4\",\n",
       "                    \"value\": 50\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\",\n",
       "                    \"value\": 48\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u65b0\\u7586\",\n",
       "                    \"value\": 41\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\",\n",
       "                    \"value\": 30\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e91\\u5357\",\n",
       "                    \"value\": 29\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u897f\",\n",
       "                    \"value\": 28\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": 24\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9ed1\\u9f99\\u6c5f\",\n",
       "                    \"value\": 23\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\",\n",
       "                    \"value\": 23\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9752\\u6d77\",\n",
       "                    \"value\": 18\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\",\n",
       "                    \"value\": 12\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": 11\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\",\n",
       "                    \"value\": 10\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\",\n",
       "                    \"value\": 8\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\",\n",
       "                    \"value\": 6\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\",\n",
       "                    \"value\": 4\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7518\\u8083\",\n",
       "                    \"value\": 4\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6fb3\\u95e8\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\",\n",
       "                    \"value\": 1\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"aspectScale\": 0.75,\n",
       "            \"nameProperty\": \"name\",\n",
       "            \"selectedMode\": false,\n",
       "            \"zoom\": 1,\n",
       "            \"mapValueCalculation\": \"sum\",\n",
       "            \"showLegendSymbol\": true,\n",
       "            \"emphasis\": {},\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"2022\\u5e748\\u670821\\u65e5_\\u75ab\\u60c5\\u5206\\u5e03\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"continuous\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 1000,\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"inverse\": false,\n",
       "        \"splitNumber\": 5,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"showLabel\": true,\n",
       "        \"itemWidth\": 20,\n",
       "        \"itemHeight\": 140,\n",
       "        \"borderWidth\": 0\n",
       "    }\n",
       "};\n",
       "                chart_3026991247044c4396c3824afa37cd8d.setOption(option_3026991247044c4396c3824afa37cd8d);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x12ffbd550>"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3 = df.sort_values(by=['nowConfirm'], ascending=False)[0:]\n",
    "df3 = df3.drop(df3[df3['nowConfirm'] == 0].index)\n",
    "\n",
    "lst = list(zip(df3['province'].values.tolist(),\n",
    "           df3['nowConfirm'].values.tolist()))\n",
    "map = (\n",
    "    Map()\n",
    "    .add(\"\", lst, 'china')\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=f'{date}_疫情分布'),\n",
    "        visualmap_opts=opts.VisualMapOpts(\n",
    "            max_=1000,\n",
    "            min_=0,\n",
    "            is_piecewise=False)\n",
    "    )\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))\n",
    ")\n",
    "map.render_notebook()\n"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "efbf56fc117e418e44edda1cb10ef72e1d236bfeb453c90c79d8abd3fc7dd926"
  },
  "kernelspec": {
   "display_name": "Python 3.8.8 64-bit ('venv0': venv)",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "metadata": {
   "interpreter": {
    "hash": "d606165cd0af856767b90bbc7a0a49e983a164d2504fab8c5191c5756f55e227"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
